package com.libl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.libl.mapper.DtsGoodsAttributeMapper;
import com.libl.pojo.DtsGoodsAttribute;
import com.libl.service.DtsGoodsAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DtsGoodsAttributeServiceImpl implements DtsGoodsAttributeService {
    @Autowired
    DtsGoodsAttributeMapper attributeMapper;

    @Override
    public List<DtsGoodsAttribute> findAttributesByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsAttribute> wrapper= new LambdaQueryWrapper<>();

        wrapper.eq(DtsGoodsAttribute::getGoodsId, id);
        wrapper.eq(DtsGoodsAttribute::getDeleted, false);

        List<DtsGoodsAttribute> attributeList = attributeMapper.selectList(wrapper);

        return attributeList;
    }

    @Override
    public void deleteByGoodsId(Integer id) {
        LambdaQueryWrapper<DtsGoodsAttribute> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DtsGoodsAttribute::getGoodsId, id);

        attributeMapper.delete(wrapper);
    }

    @Override
    public void insert(DtsGoodsAttribute attribute) {
        attribute.setAddTime(new Date());
        attribute.setUpdateTime(new Date());
        attribute.setDeleted(false);


        attributeMapper.insert(attribute);
    }

    @Override
    public void updateByGoodsId(Integer id) {
        LambdaUpdateWrapper<DtsGoodsAttribute> wrapper = new LambdaUpdateWrapper();
        wrapper.eq(DtsGoodsAttribute::getGoodsId, id);

        DtsGoodsAttribute attribute = new DtsGoodsAttribute();
        attribute.setDeleted(true);

        attributeMapper.update(attribute,wrapper);
    }

}
